class ListControl extends List implements MovieClipEvent, ChangeEventExtended {
private var base:MovieClip;
private var listView:ListView;
private var SCROLL_WIDTH:Number=18;
private var pSize:Point;
private var sc:ScrollControl;
private var MARGIN:Number=0;

	function ListControl(container:MovieClip, name:String, view:ListView) {
		super(container, name);
		if (view==undefined) {
			listView=new ListViewClassic();
		} else {
			listView=view;
		}
	}
	
	function getView():ListView {
		return listView;
	}
	
	function select() {
		super.select();
		var iSel:Collection=new Collection();
		for(var h=0; h< collection.getItems().length;h++){
			for(var i=0; i< _selectedItems.getItems().length;i++){
				if(collection.getItems()[h].getKey() == _selectedItems.getItems()[i].getKey()){
				getView().selectItem(collection.getItemAt(h));
				iSel.addCollectionItem(collection.getItemAt(h));
				} else {
				if(iSel.getIndexOf(collection.getItemAt(h).getKey())==undefined)
				getView().normalItem(collection.getItemAt(h));
				}//fin de if
			} // fin de segundo for
		} // fin de primer for
	}
	
	function draw(){
		reDraw();
	}
		
	function reDraw(){
		listView.reset();
		//borro todos los items seleccionados
		_selectedItems.removeAll();
		//Creo el movieBase
		super.removeMovieClip(base);
		base=createMovieClip();
		base._x=getLocation().getX();
		base._y=getLocation().getY();
		
		//tengo que setearle propiedades porque el flash es puto
		base.width=getSize().getX();
		//base.width=getSize().getX()-SCROLL_WIDTH;
		
		base.height=getSize().getY();
		
		//dibujo el borde y la maskara
		listView.border(base); //listView.border(//el movie Base);
		
		//Hago el for de la coleccion
		var nPosY:Number=MARGIN;
		var nAlto:Number=listView.getItemSize().getY();
	
		for(var i:Number=0;i < collection.getItems().length;i++){
			var item:MovieClip=createMovieClip(base);
			var ci:CollectionItem=collection.getItems()[i];
			//llamo a newItem por cada item
			listView.newItem(ci, item);
			item._y=nPosY;
			nPosY+=nAlto;
			item.index=i;
			MovieClipHelper.setEventListener(item,this);
		};
		
		if(checkScroll() && pSize==undefined){
			pSize=getSize();
			setSize(new Point(getSize().getX()-SCROLL_WIDTH, getSize().getY()));
			reDraw();
		} else if(!checkScroll() && pSize!=undefined){
			setSize(pSize);
			reDraw();
		} 
		//Dibujo el Scroll (antes lo borro);
				
		if(checkScroll()){
			super.removeMovieClip(sc.getClip());
			sc=new ScrollControl(base._parent, undefined, getView().getScrollView());
			sc.setSize(new Point(SCROLL_WIDTH, base.height));
			sc.setLocation(new Point(base._x+base.width-listView.getBorderSize(), getLocation().getY()));
			sc.setMin(getLocation().getY());
			sc.setMax(getLocation().getY() - ( Math.abs( (listView.getMask()._y + listView.getMask()._height) - (base._y + base._height))));
			sc.setStep(listView.getItemSize().getY());
			sc.draw();
			sc.addChangeEvent(this);
			listView.getBack()._height=base._height+listView.getItemSize().getY();
			sc.enable();
		} else {
			sc.disable();
			super.removeMovieClip(sc.getClip());
		}
				
	}
	
	private function checkScroll():Boolean{
		return listView.getMask()._height + listView.getBorderSize() < base._height;
	}
	
	function onPress(source:MovieClip):Void{
		setSelectionIndex(source.index);
	};
	function onRelease(source:MovieClip):Void{
		if(_selectedItems.getIndexOf(getItemAt(source.index).getKey())==undefined)
		getView().normalItem(getItemAt(source.index), source);
	};
	function onReleaseOutside(source:MovieClip):Void{
		if(_selectedItems.getIndexOf(getItemAt(source.index).getKey())==undefined)
		getView().normalItem(getItemAt(source.index), source);
	};
	function onRollOut(source:MovieClip):Void{
		if(_selectedItems.getIndexOf(getItemAt(source.index).getKey())==undefined)
		getView().normalItem(getItemAt(source.index), source);	
	};
	function onRollOver(source:MovieClip):Void{
		if(_selectedItems.getIndexOf(getItemAt(source.index).getKey())==undefined)
		getView().hoverItem(getItemAt(source.index), source);
	};
	
	function changedExtended(source:Control){
		base._y=ScrollControl(source).getValue();
	};
	function changed(){ // AL PEDO COMO ELLA SOLA
	}

}